package com.itheima.template;

import com.baidu.aip.face.AipFace;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;

/**
 * @Author：wsm
 * @Date：2021/12/21/19:51
 * @Description：
 */
public class CheckFaceTemplate {
    @Autowired
    private AipFace client;
  public void checkFace(String url) {

        // 传入可选参数调用接口
        HashMap<String, String> options = new HashMap<String, String>();
        options.put("face_field", "age");
        options.put("max_face_num", "2");
        options.put("face_type", "LIVE");
        options.put("liveness_control", "NONE");


        String imageType = "URL";
        // 人脸检测   https://tanhua-img12345.oss-cn-beijing.aliyuncs.com/2021/12/23bc382241-c0ec-4bd4-815f-e73fa4cf2b38.jpg
        JSONObject res = client.detect(url, imageType, options);
      Integer error_code = (Integer) res.get("error_code");
      if (error_code!=0){
          throw  new RuntimeException("您上传的头像不太受欢迎哦");
      }
      System.out.println(res.toString(2));

    }
}
